<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>事件</title>
</head>

<body>
  <div id="root">

    <div @click="fn1">
      父div
      <!-- 阻止冒泡 源头中阻止 -->
      <div @click.stop="fn2">子div</div>
    </div>

    <hr>
    <!-- 阻止默认行为 -->
    <div @click="fn1">
      父类

      <a href="http://www.baidu.com" @click.prevent.stop="fn3">百度一下</a>
    </div>

    <!-- 事件绑定一次 .once 防抖 -->
    <div @click.once="fn4">
      只绑定一次
    </div>
    <div @click="fn4">
      只绑定N次
    </div>

    <!-- 绑定的元素本身触发时才触发回调 -->
    <ul @click.self="fn5()">
      <li>你好世界</li>
    </ul>


  </div>

  <script src="./lib/vue.js"></script>
  <script>
    new Vue({
      el: '#root',
      data: {
        num: 1
      },
      // 事件方法实现
      methods: {
        fn1() {
          console.log('父')
        },
        fn2() {
          console.log('子')
        },
        fn3(evt) {
          console.log('统计中')
          // console.log(evt.target.getAttribute('href'))
          // ajax 
          setTimeout(() => {
            //location.href = evt.target.getAttribute('href')
            console.log('完成了')
          }, 2000);
          // console.log('aaaa')
        },
        fn4() {
          console.log('aaa')
        },
        fn5() {
          console.log('ul')
        }
      }
    })

  </script>
</body>

</html>